package com.lagou.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * 传递ip拦截器
 */
@Activate(group = CommonConstants.PROVIDER)
public class TransportIPFilter implements Filter {


    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        //从RpcContext中获取IP并打印
        String clientIP = RpcContext.getContext().getAttachment("clientIP");
        System.out.println("请求的IP地址为：" + clientIP);

        return invoker.invoke(invocation);

    }
}
